package com.wandian.news.adapter;

import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mylib.libcore.config.RouterConfig;
import com.mylib.libcore.utils.UIUtils;
import com.wandian.news.R;
import com.wandian.news.bean.WXTopBean;


/**
 * @author Administrator
 * @date 2019/12/16-13:32
 * @description 适配器
 **/
public class WXTopRecycleAdapter extends BaseQuickAdapter<WXTopBean.NewslistEntity, BaseViewHolder> {

    private String value;

    public WXTopRecycleAdapter(int layoutResId, String type) {
        super(layoutResId);
        this.value = type;
    }


    @Override
    protected void convert(BaseViewHolder helper, WXTopBean.NewslistEntity item) {

        try {
            RelativeLayout rl_item_zx = helper.getView(R.id.rl_item_zx);
            RelativeLayout rl_item_ad = helper.getView(R.id.rl_item_ad);
            rl_item_ad.setVisibility(View.GONE);


            TextView tv_time = helper.getView(R.id.tv_time);
            TextView tv_form = helper.getView(R.id.tv_form);
            TextView tv_desc = helper.getView(R.id.tv_desc);
            TextView tv_zx_title = helper.getView(R.id.tv_zx_title);
            if(!UIUtils.isEmpty(item.getCtime())){
                if(item.getCtime().length()>10){
                    tv_time.setText(""+item.getCtime().substring(0,10));
                }else {
                    tv_time.setText(""+item.getCtime());
                }
            }

            if(!UIUtils.isEmpty(item.getViews())){
                tv_desc.setText(item.getViews());
            }
            if(!UIUtils.isEmpty(item.getSource())){
                tv_form.setText(item.getSource());
            }
            if(!UIUtils.isEmpty(item.getTitle())){
                tv_zx_title.setText(item.getTitle());
            }

            rl_item_zx.setOnClickListener(v -> {
                Bundle bundle = new Bundle();
                bundle.putString("url",item.getUrl());
                bundle.putString("title",item.getTitle());
                ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_WEB).with(bundle).navigation();
            });

        } catch (Exception e) {
            e.printStackTrace();
        }

    }


}
